# -*- coding: utf-8 -*-

import os
import shutil
import stat


def get_files(dir):
    """return files in this dir"""
    if not dir or not os.path.isdir(dir):
        return []
    names = os.listdir(dir)
    files = []
    for name in names:
        name = os.path.join(dir, name)
        if os.path.isfile(name):
            files.append(name)
    return files

def ensure_dir_exists(dirPath):
	"""as her name"""
    if not os.path.exists(dirPath):
        try:
            os.makedirs(dirPath)
        except OSError, e:
            if not e.args[0] in (183, 17):
                raise

def ensure_pdir_exists(path):
	"""as her name"""
    parent_dir = os.path.dirname(path)
    if not os.path.exists(parent_dir):
        try:
            os.makedirs(parent_dir)
        except OSError, e:
            if not e.args[0] in (183, 17):
                raise
            
def ensure_dirs_exists(*dirPaths):
	"""as her name"""
    for dirPath in dirPaths:
        ensure_dir_exists(dirPath)
